<template>
	<view class="pt">
	
	
		<view class="content" >
			<view class="help_information">
				<text class="hm">请输入帮助信息:</text>
				<textarea :maxlength="100" v-model="addcs.help_information" class="help" placeholder="请输入帮助信息,限制100字" />
			</view>
			<view class="location m">
				<text class="h">取货地点:</text>
				<input type="text"    v-model="addcs.pick_location" value="" class="qu" placeholder="输入取货地点" />
				<uni-icons type="location" size="16"></uni-icons>
			</view>
			<view class="location m">
				<text class="h">跑腿类型:</text>
				<input :disabled="true" :hold-keyboard="true" :adjust-position="false" @click="this.isPickShow = !this.isPickShow" type="text"  v-model="methods"   value="" class="qu" placeholder="点击选择跑腿类型" />	
				<uni-icons type="location" size="16"></uni-icons>
			</view>
			<view class="money m">
				<text class="h">跑腿金额:</text>
				<input type="number"    v-model="addcs.money" value="" class="qu" placeholder="输入金额" />
				<uni-icons type="arrowright" size="16"></uni-icons>
			</view>
			<view class="location m">
				<text class="h">性别限制:</text>
				<input :disabled="true" :hold-keyboard="true" :adjust-position="false" @click="this.isPickShowSex = !this.isPickShowSex" type="text"  v-model="sex"   value="" class="qu" />	
				<uni-icons type="location" size="16"></uni-icons>
			</view>
			<view class="tip">
				<view class="tt">
					如果需要代替买东西，可以直接在帮助内容输入，当面付款。
				</view>
				<view class="yuan">
					跑腿费
				</view>
				<view class="yuan1">
					{{addcs.money ? addcs.money : ''}}元
				</view>
				<button type="default"  class="btnfb" @click="fbclick">立即发布</button>
			</view>
		</view>
		
	<u-picker @confirm="changeMethod" :closeOnClickOverlay="true" @cancel="cancePick" @close="cancePick" title="跑腿类型" :show="isPickShow" :columns="columns"></u-picker>
	
		<u-picker @confirm="changeSex" :closeOnClickOverlay="true" @cancel="cancePickSex" @close="cancePickSex" title="性别限制" :show="isPickShowSex" :columns="sexColumns"></u-picker>
	</view>
</template>

<script>
	export default {
		data () {
			return {
				addcs: {
					pick_location: '',      //取货地址
					money: '',              // 支付金额
					help_information: '',    // 额外帮助信息
					methods: 0,
					sex: '0'
				},
				methods: '',
				address: '',
				code: '',
				isPickShow: false,
				columns: [
				            ['帮送', '帮买', '帮拿','其他跑腿']
				    ],
				sexColumns: [
					['性别不限','男','女']
				],
				isPickShowSex: false,
				sex: '性别不限'
			}
		},
		computed: {
			
		},
		methods: {
			cancePickSex () {
				this.isPickShowSex = false
			},
			changeSex (e) {
				this.sex = e.value[0]
				this.isPickShowSex = false
				if (e.value[0] == '性别不限') {
					this.addcs.sex = '0'
				}
				else if (e.value[0] == '男') {
					this.addcs.sex = '1'
				}
				else if (e.value[0] == '女') {
					this.addcs.sex = '2'
				}
			},
			cancePick () {
				this.isPickShow = false
			},
			changeMethod (e) {
				this.methods = e.value[0]
				this.isPickShow = false
				if (e.value[0] == '帮送') {
					this.addcs.methods = '0'
				}
				else if (e.value[0] ==='帮买') {
					this.addcs.methods = '2'
				}
				else if (e.value[0] == '帮拿') {
					this.addcs.methods = '3'
				}
				else if (e.value[0] == '其他跑腿') {
					this.addcs.methods = '4'
				}
				
			},
			/*
				getWnenXinCode
			*/
		   getWebXinCode () {
			   let _this = this
			   wx.login({
			   	success(res) {
					_this.code = res.code
			   	}
			   })
		   },
			/*
				返回首页
			*/
		   backfun () {
			   uni.switchTab({
			   	url: '../index/index'
			   })
		   },
			gotoaddress () {
				uni.navigateTo({
					url: '/pages/address/address'
				})
			},
			/*
				立即发布
			*/
		   fbclick () {
			   console.log(this.addcs)
			   if (this.addcs.pick_location.trim().length === 0 || this.addcs.money.trim().length === 0 || this.addcs.help_information.trim().length === 0 || this.addcs.methods.trim().length === 0) {
				   return uni.showToast({
					   title: '请输入',
					   duration: 1500,
				   	icon: 'none'
				   })
			   }
			   let re = /^[0-9]+.?[0-9]*/
			   if (!re.test(this.addcs.money)) {
				   return uni.showToast({
				   	title: '请输入正确的金额',
				   	duration: 1500,
				   	icon: 'none'
				   })
			   }
			   if (this.addcs.money < 1) {
				   return uni.showToast({
				   	title: '最少1元',
				   	duration: 1500,
				   	icon: 'none'
				   })
			   }
			   if (!/^\d+$/.test(this.addcs.money)) return uni.showToast({
				   	title: '请输入整数',
				   	duration: 1500,
				   	icon: 'none'
				   })
				let _this = this
				uni.requestSubscribeMessage({
					tmplIds: ['-YIfyEVG0k7hLER1NYtzw_sJNT9uKJWHMCl9ZcNCwwg'],
					success: async (res) => {
						if (res['-YIfyEVG0k7hLER1NYtzw_sJNT9uKJWHMCl9ZcNCwwg'] !== 'accept') return
						let prames = {
							code: _this.code,
							template_id: '-YIfyEVG0k7hLER1NYtzw_sJNT9uKJWHMCl9ZcNCwwg'
						}
						const {data: res2} = await uni.$http.post('/message/addWenXinMessage',prames)
						if (res2.status !== 200) return uni.showToast({
							icon: 'none',
							title: '订阅失败',
							duration: 2000
						})
					},
					fail: (res) => {
						console.log(res)
					},
					complete: (res) => {
						uni.navigateTo({
							url: '/pay/selectPayMethods/selectPayMethods?addErrandParams=' + JSON.stringify(this.addcs)
						})
					}
				})
		   }  
		},
		onShow() {
			
		},
		onLoad(options) {
			this.getWebXinCode()
			if (!options.address) {
				
			} else {
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.qu {
		font-size: 12px;
		color: #000000;
	}
	.help {
		border: 1px solid #F0F0F0;
		margin: 5px 10px 5px 0;
		width: 95%;
		height: 80px;
		padding: 5px;
	}
	.content {
		border-radius: 5px;
		box-shadow: 1px 1px 4px 1px #eaa58a;
		border: 1px solid #eaa58a;
		background-color: #FFFFFF;
		padding: 10px;
		margin: 50px 10px;
	}
	.h {
		font-size: 14px;
		color: #eaa58a;
		display: block;
		width: 25%;
	}
	.hm {
		font-size: 14px;
		color: #eaa58a;
		display: block;
		width: 45%;
	}
	.m {
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1px solid #F0F0F0;
		margin-bottom: 5px;
		padding: 3px;
	}
	input {
		
	}
	.tip {
		margin-top: 20px;
		text-align: center;
		.tt {

			color: #e74a2d;
			font-size: 14px;
		}
		.yuan {
			margin-top: 10px;
			font-size: 12px;
			color: #C0C0C0;
		}
		.yuan1 {
			font-size: 14px;
			color: #C00000;
			margin-bottom: 10px;
		}
	}
	.btnfb {
		background-color: #e74a2d;
		color: #FFFFFF;
		font-size: 14px;
		border-radius: 10px;
	}
</style>
